package com.cheer.job;

import com.cheer.entity.MallProductEntity;
import com.cheer.service.MallCategoryProductRelationService;
import com.cheer.service.MallProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自动变为暂未开启
 *
 * @author cheer
 */
@Component
@Slf4j
public class ProductAutoResetJob {

    @Autowired
    private MallProductService mallProductService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void containerDelete() {
        try {
            List<MallProductEntity> list = mallProductService.list();
            for (MallProductEntity mallProductEntity : list) {
                try {
                    if (mallProductEntity.getSpecial()) {
                        MallProductEntity update = new MallProductEntity()
                                .setId(mallProductEntity.getId())
                                .setReset(true);
                        mallProductService.updateById(update);
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

}
